package leetcode.to1000;

import org.junit.Test;

import java.util.Deque;
import java.util.LinkedList;

public class T0739 {

        public int[] dailyTemperatures(int[] temperatures) {
            if(temperatures.length<=0){
                return temperatures;
            }
            int[] dp=new int[temperatures.length];
            Deque<Integer> stack=new LinkedList<>();
            for(int i=0;i<temperatures.length;i++){
                while(!stack.isEmpty()&&temperatures[i]>temperatures[stack.peekLast()]){
                    dp[stack.peekLast()]=i-stack.peekLast();
                    stack.removeLast();
                }
                stack.addLast(i);
            }
            return dp;
        }

    @Test
    public void test(){
        int[] dp=new int[]{73,74,75,71,69,72,76,73};
        dailyTemperatures(dp);

    }
}
